import uploadImg from '@/libs/upload-img'
import request from '@/libs/request';
import {api} from '@/packagePages/pages/order/libs/api.js';
let _self;
export const index =  {
	props: {
		show: {type: Boolean,default: false},
		price: {type: Number,default: 0},
		title: {type: String,default: ""},
		payData:{type: Object,default: {}}
	},
	data() {
		return {
			host:process.env.HOST,
			showBox:false,
			boxTitle:this.title,
			
			payType:{
				"item":[{"name":"公对公转账","value":"1"},{"name":"线上支付","value":"2"},{"name":"对私支付","value":"3"}],
				"index":1,
				"key":"name",
			},
			transferType:{
				"item":[{"name":"客户付款","value":"1"},{"name":"业务员代收","value":"2"}],
				"index":0,
				"key":"name",
			},
			formData:{"pay_money":this.price,"pay_mode":"3","transfer_type":"","pay_type":""},
			rules:{}
		}
	},
	
	
	watch:{
		show(val){
			this.showBox=val;
			if(val){
				this.initData();
			} 
			
		},
		
		price(val){
			this.formData["pay_money"]=val;
		},
		
		showBox(val){
			this.$emit('update:show', val);
		},
		title(val){this.boxTitle=val;},

	},
	created() {
		_self = this;

	},
	
	methods: {
		async initData(){

			this.formData["pay_money"]=this.price;
			
			let member=uni.getStorageSync('MEMBER_INFO');
			this.payType.item=[{"name":"公对公转账","value":"1"}];
			if(member["account_num"]=="002"){
				this.payType.item.push({"name":"线上支付","value":"2"});
				this.formData["pay_mode"]="2";
				this.formData["transfer_type"]="1";
				this.formData["pay_type"]="客户付款";
			}
			if(member["pay_code"]&&member["pay_code"].length>0){
				this.payType.item.push({"name":"对私支付","value":"3"});
			}
			
		},
		
		
		cancel(e){
			this.showBox=false;
		},
		confirmBox(e){
			
			if(isNaN(Number(this.formData["pay_money"]))){
				uni.showToast({icon:"none",title:"付款金额必须为数字！"});
				return false;
			}
			
			if(Number(this.formData["pay_money"])<=0){
				uni.showToast({icon:"none",title:"付款金额必须大于0！"});
				return false;
			}
			
			
			this.showBox=false;
			this.$emit('update:payData',{});
			this.$emit('update:payData',this.formData);
			
		},
		submitForm(){
			
		},
		
		selectChange: function(e) {
			let index=e.detail.value;
			let key=e.currentTarget.dataset["key"];
			
			switch(key){
				case "pay_mode":
					this.payType["index"] = index;
					this.formData["pay_mode"]=this.payType["item"][index].value;
					this.formData["pay_type"]=this.payType["item"][index].name;
				break;
				case "transfer_type":
					this.transferType["index"] = index;
					this.formData["transfer_type"]=this.transferType["item"][index].value;
					this.formData["pay_type"]=this.transferType["item"][index].name;
				break;
			}

		},
	

	}
}